﻿var salaryMonth = null;
var salaryAmount = null;
var saveBtn = null;
var backBtn = null;

$(function(){
	salaryMonth = $("#salaryMonth");
	salaryAmount = $("#salaryAmount");
	saveBtn = $("#save");
	backBtn = $("#back");

	salaryMonth.next().html("*");
	salaryAmount.next().html("*");
	salaryAmount.on("focus",function(){
		validateTip(salaryAmount.next(),{"color":"#666666"},"* 确认账户金额",false);
	}).on("blur",function(){

		if(salaryAmount.val() != null && salaryAmount.val().length > 1
				&& salaryAmount.val().length < 10){
			validateTip(salaryAmount.next(),{"color":"green"},imgYes,true);
		}else{
			validateTip(salaryAmount.next(),{"color":"red"},imgNo+" 账户金额有误",false);
		}
	});
	function validateDateTime(dateTimeString) {
		console.log(dateTimeString)
		var datetimeParts = dateTimeString.split("T");
		console.log(datetimeParts)
		var datePartSplit = datetimeParts[0];
		var timePartSplit = datetimeParts[1];
		var formattedDatetime = datePartSplit + " " + timePartSplit;
		console.log(formattedDatetime)
		// 正则表达式匹配
		var regex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/;

		if (!regex.test(formattedDatetime)) {
			return false; // 日期时间格式不正确
		}
		return true; // 日期时间格式和值都是有效的
	}
	salaryMonth.on("focus",function(){
		validateTip(salaryMonth.next(),{"color":"#666666"},"请选择日期",false);
	}).on("blur",function(){
		console.log(salaryMonth.val())
		console.log(validateDateTime(salaryMonth.val()));
		if(salaryMonth.val() != null && validateDateTime(salaryMonth.val())){
			validateTip(salaryMonth.next(),{"color":"green"},imgYes,true);
		}else{
			validateTip(salaryMonth.next(),{"color":"red"},imgNo+" 日期格式错误",false);
		}
	});
	
	saveBtn.on("click",function(){
		salaryAmount.blur();
		salaryMonth.blur();
		if(salaryAmount.attr("validateStatus") == "true"
			&& salaryMonth.attr("validateStatus") == "true"){
			if(confirm("确定提交数据吗？")){
				$("#salaryForm").submit();
			}
		}
	});
	
	backBtn.on("click",function(){
		//alert("modify: "+referer);
		if(referer != undefined 
			&& null != referer 
			&& "" != referer
			&& "null" != referer
			&& referer.length > 4){
		 window.location.href = referer;
		}else{
			history.back(-1);
		}
	});
});